<template>
    <div class="businessDetails hasFoot ">
        <HeaderNav3 :activeIndex="activeIndex"></HeaderNav3>
        <Contact></Contact>
        <Ad></Ad>
        <div class="businessDetails-item wrap" v-for="item in items">
            <div class="title">
                <p>{{item.post_title}}</p>
            </div>
            <p>
                <span>{{item.published_time}}</span>
            </p>
            <div class="text" v-html="html">
            </div>
        </div>
    </div>
        
</template>

<script>
import HeaderNav3 from "@/components/HeaderNav3.vue"
import Contact from '@/components/Contact.vue'
import Ad from '@/components/Ad.vue'
import { V1_GET_NEWS } from "@/config/api"

export default {
	components:{
        Contact,
        Ad,
        HeaderNav3
	},
    activated(){ 
        this.$store.commit("IS_SHOW_ALERT",true)
        if(this.$route.query.id != this.id) {
            this.getData();
            this.id=this.$route.query.id;
        }
        // console.log(this.items);
    }, 
    computed:{
        // activeIndex(){
            // return  ?"6":"6"
            // if(this.items[0].post_type==3){
            //     this.activeIndex="5"
            // }
            // if(this.items[0].post_type==4){
            //     this.activeIndex="6"
            // }
        // }
    },
    methods:{
        getData(){
            this.$http.get(V1_GET_NEWS+this.$route.query.id,{
            }).then(res=>{
                if(res.data.success){
                    this.items=res.data.infor;
                    this.html=this.escape2Html(res.data.infor[0].post_content);
                    this.items.map((item) => {
                        var da = item.published_time*1000;
                        da = new Date(da);
                        var year = da.getFullYear()+'年';
                        var month = da.getMonth()+1+'月';
                        var date = da.getDate()+'日';
                        item.published_time=[year,month,date].join('');
                    })
                    if(res.data.infor[0].post_type==2){
                         this.activeIndex="5";
                    }else{
                        this.activeIndex="6";
                    }
                    
                }
            })
        },
        escape2Html(str) {
            var arrEntities={'lt':'<','gt':'>','nbsp':' ','amp':'&','quot':'"'};
            return str.replace(/&(lt|gt|nbsp|amp|quot);/ig,function(all,t){return arrEntities[t];});
        }
    },
    mounted(){
       this.getData(); 
    },
    data(){
        
        return{
         items:[],
         id:this.$route.query.id,
         html:[],
        "activeIndex":"",
        }
    },
   
}
</script>
<style lang="scss">
    @import "../style/loanTransaction";
 .businessDetails{
    .businessDetails-item{
        width: 783px;
        margin-top: 80px ;
        margin-bottom: 80px;
        .title{
            p{
                text-align: center;
                font-size:26px;
                color:$color6;
            }
        }
        span{
            display: block;
            margin-top: 30px;
            text-align: center;
            color: #999999;
            font-size: 14px;
        }
        img{
            width: 783px;
            height: 441px;
        }
        .text{
            margin-top: 40px;
            color: #333333;
            p{
                text-indent: 28px;
                line-height: 25px;
            }
            img{
                margin: 20px 0;
            }
        }
    }
     
    
}
</style>